/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package conf2;

import conf2.net.Message;
import java.awt.Frame;
import javax.swing.JOptionPane;

/**
 *
 * @author Administrator
 */
class MessageBailoutDialog {

    public static void show(Frame parent, Message m, Class expected) {
        Throwable th = new Throwable();
        StackTraceElement elem = th.getStackTrace()[1];
        String className = elem.getClassName();
        String methodName = elem.getMethodName();
        int lineNr = elem.getLineNumber();
        Class received = m.getData().getClass();

        String msg = String.format(
                "Communication didn't work out.\n"+
                "Expected: %s\nGot: %s\n\nSent from %s, %s:%d.\nReceived in %s, %s:%d",
                expected.getCanonicalName(), received.getCanonicalName(),
                m.getCreatorClassName(), m.getCreatorMethodName(), m.getCreatorLineNr(),
                className, methodName, lineNr);

        JOptionPane.showMessageDialog(parent, msg, "Communication breakdown, baby", JOptionPane.ERROR_MESSAGE);
    }
}
